//
//  Extension+UIBarButtonItem.swift
//  PHWeibo
//
//  Created by 潘荟 on 16/7/19.
//  Copyright © 2016年 BAT. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    convenience init(title:String? = nil,imgName:String? = nil,target: AnyObject?, action: Selector) {
        self.init()
        
        let btn = UIButton()
        if let tit = title {
            btn.setTitle(tit, forState: UIControlState.Normal)
            btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
            btn.titleLabel?.font = UIFont.systemFontOfSize(15)
        }
        
        if let img = imgName {
            btn.setImage(UIImage(named: img), forState: UIControlState.Normal)
        }
        
        btn.sizeToFit()
        btn.addTarget(self, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        self.customView = btn
    }
}
